<?php
App::uses('Component','Controller');
class JqgridSearchComponent extends Component{
	
    //Genera el array de condiciones para busqueda
    function generarCondicionesBusqueda($nombreModelo,$searchField,$searchString){
        $conditions=array();
        if($_GET['_search']=="true"){
            $cond = $nombreModelo.".".$searchField;

            //---Igual
            if($_GET['searchOper']=='eq'){
                    $conditions[$cond] = $searchString;
            }

            //---Contiene
            if($_GET['searchOper']=='cn'){				
                    $conditions[$cond." LIKE"] = '%'.$searchString.'%';
            }

            //---Diferente
            if($_GET['searchOper']=='ne'){				
                    $conditions[$cond." <>"] = $searchString;
            }

            //---Inicia con
            if($_GET['searchOper']=='bw'){				
                    $conditions[$cond." LIKE"] = $searchString.'%';
            }

            //---No Contiene
            if($_GET['searchOper']=='nc'){				
                    $aux[$cond." LIKE"] = '%'.$searchString.'%';
                    $conditions['NOT'] = $aux;
            }

        }

        return $conditions;
    }
}
?>